route.ts
基本信息
- 类型: API 路由
- 路径:
./src/app/api/prompts/[id]/route.ts - 路由:
/api/prompts/[id]
概述
单个 Prompt 的详情、更新和删除接口。支持获取 Prompt 详情、更新内容、软删除 Prompt。
HTTP 方法
- GET: 获取 Prompt 详情
- PATCH: 更新 Prompt
- DELETE: 软删除 Prompt
路径参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| id | string | 是 | Prompt ID |
GET - 获取 Prompt 详情
响应
成功 (200)
{
"id": "prompt_id",
"title": "Prompt 标题",
"slug": "prompt-title",
"description": "描述",
"content": "内容",
"type": "TEXT",
"author": { ... },
"category": { ... },
"tags": [ ... ],
"versions": [ ... ],
"voteCount": 10,
"hasVoted": true
}
未找到 (404)
{
"error": "not_found",
"message": "Prompt not found"
}
私有访问限制 (403)
{
"error": "forbidden",
"message": "This prompt is private"
}
PATCH - 更新 Prompt
Body 参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| title | string | 否 | 新标题 |
| description | string | 否 | 新描述 |
| content | string | 否 | 新内容 |
| type | enum | 否 | 类型: TEXT, IMAGE, VIDEO, AUDIO, SKILL |
| structuredFormat | enum | 否 | 结构化格式 |
| categoryId | string | 否 | 分类 ID(null 表示移除) |
| tagIds | string[] | 否 | 标签 ID 数组 |
| contributorIds | string[] | 否 | 贡献者 ID 数组 |
| isPrivate | boolean | 否 | 是否私有 |
| mediaUrl | string | 否 | 媒体 URL |
| bestWithModels | string[] | 否 | 最佳模型 |
| bestWithMCP | object[] | 否 | MCP 配置 |
| workflowLink | string | 否 | 工作流链接 |
响应
成功 (200)
返回更新后的完整 Prompt 对象
错误
未授权 (401)
{
"error": "unauthorized",
"message": "You must be logged in"
}
无权限 (403)
{
"error": "forbidden",
"message": "You can only edit your own prompts"
}
验证失败 (400)
{
"error": "validation_error",
"message": "Invalid input"
}
DELETE - 软删除 Prompt
删除权限规则
- 管理员: 可以删除任何 Prompt
- 所有者: 只能删除自己因质量问题被下架的 Prompt
响应
成功 (200)
{
"success": true,
"message": "Prompt soft deleted"
}
错误
无权限 (403)
{
"error": "forbidden",
"message": "Prompts are released under CC0 and cannot be deleted. Contact an admin if there is an issue."
}
已删除 (400)
{
"error": "already_deleted",
"message": "Prompt is already deleted"
}
依赖
next/server- Next.js 服务器组件next/cache- 缓存重新验证zod- 输入验证@/lib/auth- 认证@/lib/db- Prisma 数据库客户端@/lib/ai/embeddings- AI 嵌入生成@/lib/slug- Slug 生成@/lib/ai/quality-check- 质量检查
权限
- GET: 公开访问(私有 Prompt 仅作者可访问)
- PATCH: 仅作者或管理员
- DELETE: 管理员 或 Prompt 所有者(仅针对因质量问题被下架的 Prompt)
注意事项
- 更新标题会自动重新生成 slug
- 内容变更会自动创建新版本
- 内容变更会触发质量检查和嵌入重新生成
- 删除是软删除(设置 deletedAt 字段)